from routes.util import URLGenerator
from routes import Mapper
import logging

map = Mapper()
map.minimization=False

def fix_controller(environ, result):
    result['controller'] = "topics.%s.views:%s" % (result['c'], result['c'].upper())
    del result['c']
    return True

map.connect(None, '/{c}/{action}', conditions=dict(function=fix_controller))
map.connect("home", "/", controller="views:MainPage", action="index")

map.redirect('/{url:.*}/', '/{url}', _redirect_code='301 Moved Permanently')
# Redirect to default action of "index" for anything that does not end with "/index"
map.redirect('/{url:.*(?<!/index)}', '/{url}/index', _redirect_code='301 Moved Permanently')
